package com.zxq.demo.admin.helper;

import com.zxq.demo.admin.utils.JobHttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zw
 * @description
 * @email 2408003640@qq.com
 * @date 2025/6/15 02:01
 */
@Slf4j
public class JobHelper {
    private static Set<String> urls = new HashSet<String>();
    public static void addUrl(String url) {
        urls.add(url);
    }
    public static String triggerJobById(Integer id) {
        if (CollectionUtils.isEmpty(urls)) {
            log.info("任务调度失败, 未发现可调度的服务");
            return "Failure";
        }
        String url = urls.stream().findAny().get();
        log.info("任务调度, 任务id: {}, url: {}", id, url);
        return JobHttpUtils.triggerJobById(url, id);
    }
}
